package io.renren.modules.car.controller;

import java.security.InvalidAlgorithmParameterException;
import java.util.Arrays;
import java.util.List;

import io.renren.common.entity.CarTypeEntity;
import io.renren.modules.car.entity.CarRelateDictReq;
import io.renren.modules.car.entity.req.CarDeleteReq;
import io.renren.modules.car.entity.req.CarSaveReq;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpStatus;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.renren.modules.car.entity.CarEntity;
import io.renren.modules.car.service.CarService;
import io.renren.common.utils.R;


/**
 * 
 *
 * @author LL
 * @email wdlyl@163.com
 * @date 2022-04-12 14:48:24
 */
@Slf4j
@RestController
@RequestMapping("/car")
@Api(value = "车辆信息", tags = { "车辆信息" })
public class CarController {
    @Autowired
    private CarService carService;
    
    /**
     * 根据相关信息查询车辆列表
     * @author zyzhao
     * @date 2022/4/13 23:16
     * @param userId
     * @return io.renren.common.utils.R
     */
    @GetMapping("/list/user/{user_id}")
    @RequiresPermissions("car:car:list")
    @ApiOperation("根据用户id返回车辆信息")
    public R list(@ApiParam("用户id") @PathVariable("user_id") String userId){
        List<CarEntity> carLists = carService.queryCarListByUserId(userId);
        
        return R.success(carLists);
    }


    /**
     * 根据车辆id查询车辆信息
     * @author zyzhao
     * @date 2022/4/14 23:16
     * @param carId
     * @return io.renren.common.utils.R
     */
    @GetMapping("/info/{carId}")
    //@RequiresPermissions("car:car:info")
    @ApiOperation("根据车辆id返回车辆信息")
    public R info(@ApiParam("车辆id") @PathVariable("carId") Integer carId){
		return carService.queryCarInfoByCarId(carId);
    
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @RequiresPermissions("car:car:save")
    @ApiOperation("保存车辆信息")
    public R save(@RequestBody CarSaveReq req){
		carService.saveCar(req);

        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @RequiresPermissions("car:car:update")
    @ApiOperation("更新车辆信息")
    public R update(@RequestBody CarSaveReq car){
        return carService.updateCar(car);
    
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    //@RequiresPermissions("F")
    @ApiOperation("根据id车辆信息")
    public R delete(@RequestBody CarDeleteReq req){
		carService.removeCar(req);

        return R.ok();
    }
    
    
    @GetMapping("/list/dict/{pid}")
    @ApiOperation("获取标签字典列表")
    public R dictList(@ApiParam("父级节点id") @PathVariable("pid") String pid){
        return carService.getDictListByPid(pid);
    }
    
    @PostMapping("/relate/dict")
    @ApiOperation("将车辆关联到标签上")
    public R relationDict(@RequestBody CarRelateDictReq req){
        return carService.relateDict(req);
    }

}
